<?php
/**
 * 主动请求企业微信接口封装
 * Created by PhpStorm.
 * User: sh01
 * Date: 2018/1/9
 * Time: 9:26
 */

namespace corpWeixin;
use corpWeixin\corpWeixinSdk\CWXTool;
use corpWeixin\corpWeixinSdk\Curl;


class CWXMessage
{
    /**
     * 主动发送消息
     * @param array $msgBody
     * @param string $msgType
     * @param string $toUsers
     * @param array $toParties
     * @param array $toTags
     * @return mixed
     */
    public function send($msgBody = array(),$msgType = 'text',$toUsers = '@all',$toParties=[],$toTags=[])
    {
        /* @var $cwxTool \corpWeixin\corpWeixinSdk\CWXTool*/
        $cwxTool = CWXTool::getInstance();
        $jsonMsg = $cwxTool->jsonMessage($msgBody,$msgType,$toUsers,$toParties,$toTags);
        $url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='.$cwxTool->getAccessToken();
        $res = Curl::httpPost($url,$jsonMsg);
        return $res;
    }
}